package HomeWork;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * 斗地主发牌器
 */

public class DouDiZhu {
    ArrayList<Poker> pokers = new ArrayList<>();

    /**
     * 初始化54张扑克牌
     */
    public void init() {
        pokers.add(new Poker("", "大王👑", 17));
        pokers.add(new Poker("", "小王👑", 16));

        int num = 0;
        String point = null;
        String color = null;
        for (int i = 3; i < 16; i++) {
            num = i;
            point = i + "";
            if (i == 11) {
                point = "J";
            } else if (i == 12) {
                point = "Q";
            } else if (i == 13) {
                point = "K";
            } else if (i == 14) {
                point = "A";
            } else if (i == 15) {
                point = "2";
            }
            for (int j = 0; j < 4; j++) {
                color = null;
                if (j == 0) {
                    color = "♥";
                } else if (j == 1) {
                    color = "♦";
                } else if (j == 2) {
                    color = "♠";
                } else if (j == 3) {
                    color = "♣";
                }
                pokers.add(new Poker(point, color, num));
            }
        }


    }

    /**
     * 洗牌
     */
    public void shuffle(){
        Collections.shuffle(pokers);
    }

    /**
     * 发牌
     */
    public void sendCard(){
        ArrayList<Poker> player01 = new ArrayList<>();
        ArrayList<Poker> player02 = new ArrayList<>();
        ArrayList<Poker> player03 = new ArrayList<>();

        sort(player01);
        sort(player02);
        sort(player03);
        System.out.println(pokers.size());
        for (int i = 0; i < pokers.size(); i++){
            if (i % 3 == 0){
                player01.add(pokers.get(i));
            }else if (i % 3 == 1){
                player02.add(pokers.get(i));
            }else if (i % 3 == 2){
                player03.add(pokers.get(i));
            }
        }

        System.out.println("玩家01：");
        System.out.println(player01);
        System.out.println("玩家02：");
        System.out.println(player02);
        System.out.println("玩家03：");
        System.out.println(player03);
    }
    public void sort(ArrayList arrayList) {
        Collections.sort(arrayList, new Comparator<Poker>() {
            @Override
            public int compare(Poker o1, Poker o2) {
                return (o1.getNum() - o2.getNum());
            }
        });
    }
}
